package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.xcity.game.common.Currency;
import com.xcity.game.common.ItemResponse;
import com.xcity.game.shop.mystery.PlayerMysteryShopItem;
import com.xcity.game.shop.mystery.template.MysteryShopItemTemplate;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class MysteryShopItemListResponse extends Response {

	protected int refreshCost; // 刷新需消耗的钻石
	protected int cd; // 下次自动刷新剩余cd(millis)
	protected List<MysteryShopItemRes> items = Collections.emptyList();
	
	public static class MysteryShopItemRes extends ItemResponse {
		protected Currency currency; // 货币类型
		protected int orgPrice; // 原价
		protected int price; // 价格
		protected byte state;
		public Currency getCurrency() {
			return currency;
		}
		public void setCurrency(Currency currency) {
			this.currency = currency;
		}
		public int getPrice() {
			return price;
		}
		public void setPrice(int price) {
			this.price = price > 0 ? price : 1; // 最低价1
		}
		public byte getState() {
			return state;
		}
		public void setState(byte state) {
			this.state = state;
		}
		public int getOrgPrice() {
			return orgPrice;
		}
		public void setOrgPrice(int orgPrice) {
			this.orgPrice = orgPrice;
		}
	}
	
	public MysteryShopItemListResponse(int serial, int refreshCost, int cd, List<PlayerMysteryShopItem> refs, int discount) {
		super(serial);
		this.refreshCost = refreshCost;
		this.cd = cd;
		if (refs != null && refs.size() > 0) {
			items = new ArrayList<MysteryShopItemRes>(refs.size());
			for (int i = 0; i < refs.size(); i++) {
				PlayerMysteryShopItem ref = refs.get(i);
				MysteryShopItemRes res = new MysteryShopItemRes();
				res.setId(i/*ref.getId()*/); // 索引表示
				res.setCount(ref.getCount());
				res.setName(ref.getName());
				res.setIcon(ref.getIcon());
				res.setDesc(ref.getDesc());
				MysteryShopItemTemplate template = ref.getTemplate();
				res.setCurrency(template.getPriceType());
				res.setOrgPrice(template.getOriginalPrice());
				res.setPrice(template.getPrice() * discount / 100);
				res.setState(ref.getState());
				res.setQuality(template.getRef().getQuality());
				items.add(res);
			}
		}
	}

	public int getRefreshCost() {
		return refreshCost;
	}

	public void setRefreshCost(int refreshCost) {
		this.refreshCost = refreshCost;
	}
	
	public int getCd() {
		return cd;
	}

	public void setCd(int cd) {
		this.cd = cd;
	}

	public List<MysteryShopItemRes> getItems() {
		return items;
	}

	public void setItems(List<MysteryShopItemRes> items) {
		this.items = items;
	}

}
